package cn.itzhao.massage.service.impl;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import cn.itzhao.massage.service.ISendMessage;

@Service
public class SendMessageImpl implements ISendMessage {

	@Autowired
	private JmsTemplate jmsTemplate;

	@Resource(name = "queueDestination")
	private Destination destination;


	public void send(final String message) {
		jmsTemplate.send(destination, new MessageCreator() {
			public Message createMessage(Session session)
					throws JMSException {
				TextMessage textMessage = session.createTextMessage(message);
				System.out.println("发送消息"+textMessage);
				return textMessage;
			}
		});
	}
}
